<!--
 * @Descripttion:
 * @version:
 * @Author: tanghao1
 * @Date: 2021-03-11 15:39:10
 * @LastEditors: tanghao1
 * @LastEditTime: 2021-03-17 09:12:52
-->
<template>
  <el-dialog
    ref="refAttr"
    :title="'选择属性'"
    :visible.sync="dialogShow"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    :hide-func-bar="true"
    :before-close="clearForm"
    highlight-current-row
    width="600px"
    @close="closeDialog"
  >
    <table-box
      ref="refSearchAttr"
      :table-config="tableConfig"
      table-height="400"
      :other-filters="otherFilters"
      :selected-arry.sync="multipleSelection"
      :off-set="-10"
      @data-change="dataChange"
      @selection-change="handleSelectionChange"
    />
    <div slot="footer">
      <el-button size="mini" @click="closeDialog">取消</el-button>
      <el-button size="mini" type="primary" @click="submitForm">确认</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { json2FormData } from '@/utils'
import { searchAttrData } from '@/api/shopauxPlat/screenTemplate' // 查询数据
export default {
  name: 'SearchAttr',
  props: {
    visible: {
      type: Boolean,
      default: false,
      required: true
    },
    detailattr: {
      type: [String, Object],
      default: ''
    },
    detailDataselect: {
      type: [String, Object],
      default: ''
    }
  },
  data() {
    return {
      isEdit: true,
      submiting: false,
      otherFilters: [],
      hasselected: [],
      tableConfig: {
        interfacePath: `${process.env.VUE_APP_BASE_API}/api/v1/filterTemplateCondition/queryAttrs`,
        pageSize: 20,
        sort: '',
        order: 'desc',
        onlySearchBar: true,
        setting: [
          {
            prop: 'code',
            label: '属性编码',
            minWidth: 130
          },
          {
            prop: 'name',
            label: '属性名称',
            minWidth: 130
          }]
      }

    }
  },
  computed: {
    dialogShow: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', val)
      }
    }
  },
  created() {
    // this.initData()
    console.log(this.detailDataselect)
  },
  methods: {
    closeDialog() {
      this.dialogShow = false
    },
    handleSelectionChange(val) {
      console.log(val)
      this.multipleSelection = val
    },
    // 提交表单处理
    submitForm() {
      if (this.multipleSelection.length === 0) {
        this.$message.warning('请选择一条数据!')
        return
      } else {
        this.$emit('refreshAttr', this.multipleSelection[0])
      }
    },
    initData() {
      // const val = { }
      // val.id = 'attrId'
      // val.value = this.detailDataselect.attrId
      // val.property = 'attrId'
      // val.operator = 'like'

      // this.otherFilters.push(val)
      const searchData = json2FormData({
        page: this.currentPage,
        rows: this.pagesize,
        order: 'desc',
        sort: '',
        onlyCountFlag: false,
        filtersRaw: JSON.stringify(this.otherFilters)
      })

      searchAttrData(searchData).then(res => {
        if (res.success === 1) {
          const { page, rows, total, records } = res.data
          const list = records
          this.total = total

          if (total <= page * rows) {
            this.allTotal = total
          }
          this.formData.list = list
          // this.formData.list = res.data.records
        }
      })
    }
  }
}
</script>
<style lang='scss' scoped>
.el-col el-col-11{margin-bottom: 20px;}
 .avatar-uploader .el-upload {
    border: 1px dashed #181717;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 120px;
    height: 120px;
    line-height: 120px;
    text-align: center;
  }
  .avatar {
    width: 120px;
    height: 120px;
    display: block;
  }
</style>

